-- aid_attrib
-- create by panyl
-- 辅助属性，对他人属性提升N%，最少提升1点

return {
    apply = function(prop, baseValue)
        -- 提升的百分比
        local v = prop[3];

        if v == 0 or baseValue <= 0 then
            return baseValue;
        end

        -- 最少提升1点
        local add = FormulaM.invoke("CALC_BIG_DIVISION", baseValue, v, 1000);
        local min_add = 1;

        -- 攻击和魔力的技能提升需要设置下限
        if ((prop[2] == "attack" or prop[2] == "magic") and prop[3] < 300) then
            min_add = math.modf(v / 60);
        end

        -- 如果是伤害减少，没有保底
        if prop[2] == "damage" then
            return baseValue - add;
        end

        return baseValue + math.max(min_add, add);
    end,

    clear = function(who, prop)
        who.dbase:deleteTemp("aid_attrib");
    end,

    desc = function(prop)
        local row = PropM.getRow(prop[1]);
        local desc = row.desc;

        if prop[2] == "damage" then
            -- 庇护光环
            desc = string.gsub(getLocStr("queen_monster_aid_desc"),
                "{0}", tostring(math.modf(prop[3] / 10)));
            return desc;
        end

        local attrib = FieldsM.getFieldName(prop[2]);
        desc = string.gsub(desc, "{0}", attrib);
        local v = math.modf(prop[3] / 10);
        desc = string.gsub(desc, "{1}", v);

        return desc;
    end,

    title = function(prop)
        local row = PropM.getRow(prop[1]);

        if prop[2] == "damage" then
            -- 庇护光环技能名称
            return SkillM.query(2210, "name");
        end

        return row.alias;
    end,

    record = function(target, prop, path)
        return false;
    end
};
